using ExampleWebApplication.Entities;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace ExampleWebApplication.Infraestruture.NHibernate.EntityMappings
{
    public class OrderMap : ClassMapping<Order>
    {
        public OrderMap()
        {
            Table("Orders");
            Id(x => x.OrderID, map => { map.Generator(Generators.Identity); map.Column("OrderID"); });
            Property(x => x.OrderDate, map => map.Column("OrderDate"));
            Property(x => x.RequiredDate, map => map.Column("RequiredDate"));
            Property(x => x.ShippedDate, map => map.Column("ShippedDate"));
            Property(x => x.Freight, map => map.Column("Freight"));
            Property(x => x.ShipName, map => { map.Column("ShipName"); map.Length(40); });
            Property(x => x.ShipAddress, map => { map.Column("ShipAddress"); map.Length(60); });
            Property(x => x.ShipCity, map => { map.Column("ShipCity"); map.Length(15); });
            Property(x => x.ShipRegion, map => { map.Column("ShipRegion"); map.Length(15); });
            Property(x => x.ShipPostalCode, map => { map.Column("ShipPostalCode"); map.Length(10); });
            Property(x => x.ShipCountry, map => { map.Column("ShipCountry"); map.Length(15); });
            ManyToOne(x => x.Customer, map => map.Column("CustomerID"));
            ManyToOne(x => x.Employee, map => map.Column("EmployeeID"));
            ManyToOne(x => x.Shipper, map => map.Column("ShipVia"));
            Bag(x => x.OrderDetails, map => { map.Inverse(true); map.Key(key => key.Column("OrderID")); }, rel => rel.OneToMany());
        }
    }
}
